package page
{
	import flash.display.Bitmap;
	import flash.display.DisplayObjectContainer;
	import flash.display.Sprite;
	import flash.events.Event;

	public class Page_logo extends Page
	{
		[Embed( source = "/logo.gif", mimeType="image/gif")]
		private const IMG_LOGO:Class;

		private var _canvas:Sprite;
		
		private var _state:int;
		private static const STATE_LOGO:int = 1;
		private static const STATE_END:int = 2;
		
		private var _logoLiftTick:int = LOGO_DURATION;
		private static const LOGO_DURATION:int = (CONFIG::debug)? 1: 48;

		public function Page_logo(parent:DisplayObjectContainer)
		{
			super(parent);
		}
		
		override protected function onEnterFrame(e:Event):void
		{
			super.onEnterFrame(e);
			
			if(_state == STATE_LOGO)
			{
				if(--_logoLiftTick < 0)
				{
					_state = STATE_END;
				}
			}
			else if(_state == STATE_END)
			{
				
			}
			
			//have to do this at last
			if(_state == STATE_END)
			{
				PageController.getInstance().selectDemo(Page_game);
			}
		}
		
		override public function enter():void
		{
			super.enter();
			_state = STATE_LOGO;
			
			initLogo();
		}
		
		private function initLogo():void
		{
			if(_canvas != null)
			{
				this.removeChild(_canvas);
			}
			_canvas = new Sprite();
			this.addChild(_canvas);

			var background:Sprite = new Sprite();
			background.graphics.beginFill(0xffffff, 1);
			background.graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight);
			background.graphics.endFill();
			_canvas.addChild(background);
			
			var logoAbacus:Bitmap = new IMG_LOGO();
			_canvas.addChild(logoAbacus);
			
			logoAbacus.x = (stage.stageWidth - logoAbacus.width) / 2;
			logoAbacus.y = (stage.stageHeight - logoAbacus.height) / 2;
			
		}
		
		override public function exit():void
		{
			
			//
			super.exit();
		}

	}
}